{% extends "layout/basic.html" %}
{% block content %}
{{ set(UiContext, 'pdoc', pdoc) }}
<div class="row">
  <div class="medium-9 columns">
    <div class="section">
      <div class="section__header">
        <h1 class="section__title">
          {% if rdoc %}
            <a href="{{ url('record_detail', {rid:rdoc._id}) }}">
              <span class="icon record-status--icon {{ model.builtin.STATUS_CODES[rdoc['status']] }}"></span>
              <span class="record-status--text {{ model.builtin.STATUS_CODES[rdoc['status']] }}">{{ rdoc.score }}</span>
            </a>
          {% endif %}
          {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) and not tdoc %}
            <form class="form--inline" action="" method="post">
              <input type="hidden" name="star" value="{{ 'true' if not psdoc.star else 'false' }}">
              <input type="hidden" name="operation" value="star">
              <button class="star{% if psdoc.star %} activated{% endif %}" type="submit">
                <span class="starred--hide"><span class="icon icon-star--outline" data-tooltip="{{ _('Star') }}"></span></span>
                <span class="starred--show"><span class="icon icon-star" data-tooltip="{{ _('Unstar') }}"></span></span>
              </button>
            </form>
          {% endif %}
          {%- if tdoc -%}
            {{ String.fromCharCode(65+tdoc.pids.indexOf(pdoc.docId)) }}
          {%- elif pdoc.pid and pdoc.pid.includes('-') -%}
            {{ pdoc.pid.split('-').join('#') }}
          {%- else -%}
            #{{ pdoc.pid|default(pdoc.docId) }}
          {%- endif -%}. {{ pdoc.title }}
        </h1>
        {% if tdoc and tdoc.pids|length <= 26 %}
          <div class="section__tools contest-problems">
            {% for pid in tdoc.pids -%}
              {% set status = tsdoc.detail[pid].status %}
              {% set pass = status == STATUS.STATUS_ACCEPTED %}
              {% set fail = status and not pass %}
              <a href="{{ url('problem_detail', pid=pid, query={tid:tdoc.docId}) }}"
                 class="{% if pass %}pass{% elif fail %}fail{% endif %}
                        {% if pid==pdoc.docId %} active{% endif %}">
                <span class="id">{{ String.fromCharCode(65+loop.index0) }}</span>
                {% if status %}<span class="icon icon-{% if pass %}check{% else %}close{% endif %}"></span>{% endif %}
              </a>
            {%- endfor %}
          </div>
        {% endif %}
      </div>
      <div class="section__body">
        <ul class="problem__tags">
          {% if not tdoc %}
            <span class="bp5-tag bp5-large bp5-minimal problem__tag-item">{{ _('ID') }}: {{ pdoc.docId }}</span>
          {% endif %}
          <span class="bp5-tag bp5-large bp5-minimal problem__tag-item icon icon-book">{{ _('problem_type.' + pdoc.config.type).format(pdoc.config.subType) }}</span>
          {% if pdoc.config.type == 'default' and pdoc.config.subType %}
            <span class="bp5-tag bp5-large bp5-minimal problem__tag-item icon icon-book">{{ _('File IO: {0}').format(pdoc.config.subType) }}</span>
          {% endif %}
          {% if pdoc.config.type != 'objective' and pdoc.config.type != 'submit_answer' %}
            <span class="bp5-tag bp5-large bp5-minimal problem__tag-item icon icon-stopwatch">{{ pdoc.config.timeMax if pdoc.config.timeMax == pdoc.config.timeMin else pdoc.config.timeMin+'~'+pdoc.config.timeMax }}ms</span>
            <span class="bp5-tag bp5-large bp5-minimal problem__tag-item icon icon-comparison">{{ pdoc.config.memoryMax if pdoc.config.memoryMax == pdoc.config.memoryMin else pdoc.config.memoryMin+'~'+pdoc.config.memoryMax }}MiB</span>
          {% endif %}
          {% if not tdoc %}
            <a class="bp5-tag bp5-large bp5-minimal bp5-interactive problem__tag-item" href="{{ url('record_main', query={pid:pdoc.docId}) }}">{{ _('Tried') }}: {{ pdoc.nSubmit }}</a>
            <a class="bp5-tag bp5-large bp5-minimal bp5-interactive problem__tag-item" href="{{ url('record_main', query={pid:pdoc.docId, status:1}) }}">{{ _('Accepted') }}: {{ pdoc.nAccept if ((not tdoc) or showAccept) else '?' }}</a>
            <span class="bp5-tag bp5-large bp5-minimal problem__tag-item">{{ _('Difficulty') }}: {{ pdoc['difficulty'] or lib.difficulty(pdoc.nSubmit, pdoc.nAccept) or _('(None)') }}</span>
            <span class="bp5-tag bp5-large bp5-minimal bp5-interactive problem__tag-item">{{ _('Uploaded By') }}: {{ user.render_inline(udoc, badge=false) }}</span>
          {% endif %}
          {% if pdoc.tag.length %}
            <span name="show_tags" class="bp5-tag bp5-large bp5-minimal bp5-interactive problem__tag-item nojs--hide icon icon-tag">{{ _('Tags') + '>' }}</span>
            {%- for tag in pdoc.tag -%}
              <span class="bp5-tag bp5-large bp5-minimal problem__tag-item tags hasjs--hide">{{ tag }}</span>
            {%- endfor -%}
          {% endif %}
        </ul>
      </div>
    </div>
    <div class="section">
      <div class="problem-content-container"><div class="problem-content" data-marker-enabled>
        <div class="section__header non-scratchpad--hide">
          <h1 class="section__title">{{ pdoc.title }}</h1>
        </div>
        {% if pdoc.content|contentLang|length > 1 %}
        <div class="section__tab-container">
          <div class="section__tab-header-wrapper">
            <ul class="section__tab-header flex-row">
              {% for k in pdoc.content|contentLang %}
              <a class="section__tab-header-item {{'tab--active' if (handler.request.query.lang or handler.user.viewLang or handler.session.viewLang or (pdoc.content|contentLang)[0] ) == k }}" data-lang="{{ k }}" href="./{{pdoc.pid|default(pdoc.docId)}}?lang={{k}}">
                {{ handler.ctx.i18n.get('__langname', k) or i18n('Unknown language') }}
              </a>
              {% endfor %}
            </ul>
          </div>
        </div>
        {% endif %}
        {% include "partials/problem_description.html" %}
      </div></div>
    </div>
    <div class="section">
      <div class="section__header">
        <h1 class="section__title">{{ _('Submit to Judge') }}</h1>
      </div>
      <div class="section__body typo">
        <form method="post" enctype="multipart/form-data">
          <div class="hasjs--hide">
            {{ form.form_select({
                label:'Code language',
                options:langRange,
                name:'lang',
                value:handler.user.codeLang
              }) }}
          </div>
          <div class="row nojs--hide" id="codelang-selector"></div>
          {{ form.form_textarea({label:'Code', columns:12, name:'code', extra_class:'monospace', autofocus:true, nospellcheck:true}) }}
          <div class="row">
            <div class="medium-12 columns">
              
              <br />
            </div>
          </div>
          <div class="row"><div class="columns">
            <input type="submit" class="rounded primary button" value="{{ _('Submit') }}">
          </div></div>
        </form>
      </div>
	  <div  name="submit_section"></div>
    </div>
  </div>
  <div class="medium-3 columns">
    {% include "partials/problem_sidebar.html" %}
  </div>
</div>

{% endblock %}
